package router

import (
	"shop-manager/internal/logic"
	"shop-manager/internal/repos/factory_rebate"
	"shop-manager/internal/vo"

	"github.com/gin-gonic/gin"
)

// 厂家返点管理
func RegisterFactoryRebate(api *gin.RouterGroup,
	factoryRebateRepo *factory_rebate.FactoryRebateRepo,
	factoryRebateLogic *logic.FactoryRebateLogic,
	handleBizRsp func(ctx *gin.Context, rsp any, err error),
	handleBizListRsp func(ctx *gin.Context, rsp any, total int64, err error),
) {
	manufacturerRebateApiGroup := api.Group("/factory_rebate")
	{
		manufacturerRebateApiGroup.POST("/create", func(ctx *gin.Context) {
			var req vo.CreateFactoryRebateReq
			if err := ctx.BindJSON(&req); err != nil {
				return
			}

			// 创建厂家返点
			rsp, err := factoryRebateLogic.CreateFactoryRebate(ctx, req)
			handleBizRsp(ctx, rsp, err)
		})

		manufacturerRebateApiGroup.POST("/update", func(ctx *gin.Context) {
			var req vo.UpdateFactoryRebateReq
			if err := ctx.BindJSON(&req); err != nil {
				return
			}
			err := factoryRebateLogic.UpdateFactoryRebate(ctx, req)
			handleBizRsp(ctx, nil, err)
		})

		manufacturerRebateApiGroup.POST("/delete", func(ctx *gin.Context) {
			var req vo.GetFactoryRebateReq
			if err := ctx.BindJSON(&req); err != nil {
				return
			}
			err := factoryRebateLogic.DeleteFactoryRebate(ctx, req)
			handleBizRsp(ctx, nil, err)
		})

		manufacturerRebateApiGroup.POST("/list", func(ctx *gin.Context) {
			var req vo.ListFactoryRebateReq
			if err := ctx.BindJSON(&req); err != nil {
				return
			}
			rsp, err := factoryRebateLogic.ListFactoryRebate(ctx, req)
			handleBizRsp(ctx, rsp, err)
		})

		manufacturerRebateApiGroup.POST("/get", func(ctx *gin.Context) {
			var req vo.GetFactoryRebateReq
			if err := ctx.BindJSON(&req); err != nil {
				return
			}
			rsp, err := factoryRebateLogic.GetFactoryRebate(ctx, req)
			handleBizRsp(ctx, rsp, err)
		})

		// 批量修改商品返点接口
		manufacturerRebateApiGroup.POST("/batch_update", func(ctx *gin.Context) {
			var req vo.BatchUpdateFactoryRebateReq
			if err := ctx.BindJSON(&req); err != nil {
				return
			}
			err := factoryRebateLogic.BatchUpdateFactoryRebate(ctx, req)
			handleBizRsp(ctx, nil, err)
		})
	}
}
